﻿using Newtonsoft.Json.Linq;
using NPortableEngine;
using Services4KouDai.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Services4KouDai.Parsers
{
    public class HoneyParser : IParser
    {
        public override void ParseJson(string json, BackData backData)
        {
            List<HoneyEntity> honeyItems = (List<HoneyEntity>)backData.ResponseData;

            JArray jarray = JArray.Parse(json);
            JToken jobj = jarray[1];

            JToken jt = jobj.SelectToken("items");

            foreach (JToken subJt in jt.Children())
            {
                HoneyEntity honeyItem = new HoneyEntity();
                honeyItem.ID = subJt.Value<string>("id");
                honeyItem.ImageUrl = subJt.Value<string>("imageUrlForIphone");
                honeyItem.ImgRatio = subJt.Value<double>("imgRatio");
                honeyItem.Name = subJt.Value<string>("name");
                honeyItem.Price = subJt.Value<string>("price");
                honeyItem.SoldOut = subJt.Value<string>("soldout");
                honeyItem.Timestamp = subJt.Value<long>("timestamp");
                honeyItem.Favorite = subJt.Value<string>("favorite");
                honeyItem.AppName = subJt.Value<string>("appName");
                honeyItem.EntranceName = subJt.Value<string>("entranceName");
                honeyItem.SubAppName = subJt.Value<string>("subAppName");
                honeyItem.ShopGrade = subJt.Value<string>("shopgrade");
                honeyItem.SubEntranceName = subJt.Value<string>("subEntranceName");
                honeyItem.ShopImg = subJt.Value<string>("shopImg");
                honeyItem.IsPreference = subJt.Value<bool>("isPreference");

                honeyItems.Add(honeyItem);
            }
        }
    }
}
